/**
 * 
 */
//24h
var CLOUD_AREA=[
	{text:'晴',min:0,max:50,src:'weather-fine.png'},
	{text:'多云',min:50,max:90,src:'weather-cloud1.png'},
	{text:'阴',min:90,max:100000,src:'weather-overcast.png'}
]
var SNOW_AREA=[
	{text:'小雪',min:0.1,max:2.4,src:'weather-snow.png'},
	{text:'中雪',min:2.5,max:4.9,src:'weather-snow.png'},
	{text:'大雪',min:5,max:9.9,src:'weather-snow.png'},
	{text:'暴雪',min:10.0,max:19.9,src:'weather-snow.png'},
	{text:'大暴雪',min:20,max:29.9,src:'weather-snow.png'},
	{text:'特大暴雪',min:30,max:10000,src:'weather-snow.png'}
]
var RAIN_AREA=[
	{text:'小雨',min:0.1,max:9.9,src:'weather-largerain.png'},
	{text:'中雨',min:10,max:24.9,src:'weather-largerain.png'},
	{text:'大雨',min:25,max:49.9,src:'weather-largerain.png'},
	{text:'暴雨',min:50.0,max:99.9,src:'weather-largerain.png'},
	{text:'大暴雨',min:100,max:249.9,src:'weather-largerain.png'},
	{text:'特大暴雨',min:250,max:10000,src:'weather-largerain.png'}
]
var WIND_ARR_DICT=[
                   {text:'北',cod:'N',sr:348.76,er:11.25},
                   {text:'北东北',cod:'NNE',sr:11.26,er:33.75},
                   {text:'东北',cod:'NE',sr:33.76,er:56.25},
                   {text:'东东北',cod:'ENE',sr:56.26,er:78.75},
                   {text:'东',cod:'E',sr:78.76,er:101.25},
                   {text:'东东南',cod:'ESE',sr:101.26,er:123.75},
                   {text:'东南',cod:'SE',sr:123.76,er:146.25},
                   {text:'南东南',cod:'SSE',sr:146.26,er:168.75},
                   {text:'南',cod:'S',sr:168.26,er:191.25},
                   {text:'南西南',cod:'SSW',sr:191.26,er:213.75},
                   {text:'西南',cod:'SW',sr:213.76,er:236.25},
                   {text:'西西南',cod:'WSW',sr:236.26,er:258.75},
                   {text:'西',cod:'W',sr:258.76,er:281.25},
                   {text:'西西北',cod:'WNW',sr:281.26,er:303.75},
                   {text:'西北',cod:'NW',sr:303.76,er:326.25},
                   {text:'北西北',cod:'NNW',sr:326.26,er:348.75}
                   ];
var WIND_SU_DICT=[
                  {level:0,ss:0,es:0.2},
                  {level:1,ss:0.3,es:1.5},
                  {level:2,ss:1.6,es:3.3},
                  {level:3,ss:3.4,es:5.4},
                  {level:4,ss:5.5,es:7.9},
                  {level:5,ss:8.0,es:10.7},
                  {level:6,ss:10.8,es:13.8},
                  {level:7,ss:13.9,es:17.1},
                  {level:8,ss:17.2,es:20.7},
                  {level:9,ss:20.8,es:24.4},
                  {level:10,ss:24.5,es:28.4},
                  {level:11,ss:28.5,es:32.6},
                  {level:12,ss:32.7,es:36.9},
                  {level:13,ss:37.0,es:41.4},
                  {level:14,ss:41.5,es:46.1},
                  {level:15,ss:46.2,es:50.9},
                  {level:16,ss:51.0,es:56.0},
                  {level:17,ss:56.1,es:null}
                  ];
var STATION_DATA_INFO={
		station_code:{
			hidden:true
		},
        station_address: {
			hidden:false,
			call:function(obj){
				return obj;
			}
		},
        station_lng: {
			hidden:true
		},
        station_lat: {
			hidden:true
		},
		data_time:{
			hidden:false,
			call:function(obj){
				return obj;
			}
		},
		rhum_in: {
			hidden:true,
			call:function(obj){
				return "室内湿度："+obj+"%";
			}
		},
		rhum_out: {
			hidden:false,
			call:function(obj){
				return "空气湿度："+obj+"%";
			}
		},
        temp_in: {
			hidden:true,
			call:function(obj){
				return "室内温度："+obj+"%";
			}
		},
        temp_out: {
        	hidden:false,
			call:function(obj){
				return "空气温度："+obj+"℃";
			}
		},
        solar_radia: {
			hidden:false,
			call:function(obj){
				return "太阳辐射："+obj+"w/m²";
			}
		},
        uv: {
			hidden:false,
			call:function(obj){
				return "紫外辐射："+obj+"MEDs";
			}
		},
        ice0_temp: {
        	hidden:false,
			call:function(obj){
				return "传感器0-地面温度："+obj+"℃";
			}
		},
        ice0_alarm: {
			hidden:false,
			call:function(obj){
				var ice=obj.charAt(0)==0?'未结冰':'结冰';
				var water=obj.charAt(1)==0?'干燥':'积水';
				var ht=obj.charAt(2)==1?'高温预警':'无高温';
				return "传感器0-"+ice+"-"+water+"-"+ht;
			}
		},
        ice0_thick: {
        	hidden:false,
			call:function(obj){
				return "传感器0-冰厚度："+obj+"mm";
			}
		},
        ice1_temp: {
        	hidden:false,
			call:function(obj){
				return "传感器1-地面温度："+obj+"℃";
			}
		},
        ice1_alarm: {
        	hidden:false,
			call:function(obj){
				var ice=obj.charAt(0)==0?'未结冰':'结冰';
				var water=obj.charAt(1)==0?'干燥':'积水';
				var ht=obj.charAt(2)==1?'高温预警':'无高温';
				return "传感器1-"+ice+"-"+water+"-"+ht;
			}
		},
        ice1_thick: {
        	hidden:false,
			call:function(obj){
				return "传感器1-冰厚度："+obj+"mm";
			}
		},
        barometer: {
			hidden:false,
			call:function(obj){
				return "气压："+obj+"Pa";
			}
		},
        wind: {
			hidden:true
		},
        wind_dirc: {
			hidden:true
		},
        win_ave: {
			hidden:true
		},
        rain_rate: {
			hidden:false,
			call:function(obj){
				return "降雨率："+obj+"%"
			}
		},
        rain_day: {
			hidden:false,
			call:function(obj){
				return "日降雨量："+obj+"mm"
			}
		},
        rain_month: {
			hidden:false,
			call:function(obj){
				return "月降雨量："+obj+"mm"
			}
		},
        rain_year: {
        	hidden:false,
        	call:function(obj){
        		return "年降雨量："+obj+"mm"
        	}
		},
        con_battery: {
        	hidden:false,
        	call:function(obj){
        		return "控制台电量："+obj+"%"
        	}
		},
        temp_extra: {
			hidden:true
		},
        soil_temp: {
			hidden:true
		},
        leaf_temp: {
			hidden:true
		},
        rhum_extra: {
			hidden:true
		},
        soil_moinst: {
			hidden:true
		},
        leaf_wet: {
			hidden:true
		}
}
var disArr=[];


/**
 * 24小时天气
 * @param {Object} rain	24小时合计降雨量
 * @param {Object} snow	24小时合计降雪量
 * @param {Object} cloud云量
 */
function getWeatherStr(rain,snow,cloud){
	var r=rain<=0.1?0:rain;
	var s=snow<=0.1?0:snow;
	var c=cloud;
	if(r!=0 && s==0){	//降雨
		for(var i=0;i<RAIN_AREA.length;i++){
			if(r>RAIN_AREA[i].min && r<RAIN_AREA[i].max){
				return RAIN_AREA[i];
			}
		}
		return RAIN_AREA[0];
	}else if(r==0 && s!=0){	//降雪
		for(var i=0;i<SNOW_AREA.length;i++){
			if(s>SNOW_AREA[i].min && s<SNOW_AREA[i].max){
				return SNOW_AREA[i];
			}
		}
		return SNOW_AREA[0];
	}else{
		for(var i=0;i<CLOUD_AREA.length;i++){
			if(c>=CLOUD_AREA[i].min && c<CLOUD_AREA[i].max && rain==0 && snow==0){
				return CLOUD_AREA[i];
			}
		}
		return CLOUD_AREA[0];
	}
}

/**
 * 获取风向风速
 * @param wd
 * @param ws
 * @returns {___anonymous1776_1777}
 */
function getWinD(wd,ws){
	var res={};
	for(var i=0;i<WIND_ARR_DICT.length;i++){
		var dict=WIND_ARR_DICT[i];
		if((wd>=WIND_ARR_DICT[0].sr && wd<=360) || (wd>=0 && wd<=WIND_ARR_DICT[0].er)){
			res.wd=dict;
			break;
		}
		if(wd>=dict.sr && wd<=dict.er){
			res.wd=dict;
			break;
		}
	}
	for(var i=0;i<WIND_SU_DICT.length;i++){
		var dict=WIND_SU_DICT[i];
		if(ws>=dict.ss &&dict.es!=null && ws<=dict.es){
			res.ws=dict;
			break;
		}else if(dict.es==null && ws>=dict.ss){
			res.ws=dict;
			break;
		}
	}
	
	return res;
	
}


function ComplexCustomOverlay(point,pointData) {
	this._point = point;
	this._pointData = pointData;
}
ComplexCustomOverlay.prototype = new BMap.Overlay();
ComplexCustomOverlay.prototype.initialize = function(map) {
	this._map = map;
	var div = this._div = document.createElement("div");
	div.style.position = "absolute";
	div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
	div.style.color = "white";
	div.style.padding = "2px";
	div.style.lineHeight = "18px";
	div.style.MozUserSelect = "none";
	div.style.border = "none";
	div.style.fontSize = "14px";
	
	this._info=[];
	var rainWarn=null
	var rainText=null;
	if(this._pointData.rain>30 && this._pointData.rain<=70){
		rainWarn = document.createElement("div");
		rainWarn.style.backgroundColor = "#FFB800";
		rainText=this._pointData.num+"-暴雨黄色预警"
	}else if(this._pointData.rain>70 && this._pointData.rain<=140){
		rainWarn = document.createElement("div");
		rainWarn.style.backgroundColor = "#FF5722";
		rainText=this._pointData.num+"-暴雨橙色预警"
	}else if(this._pointData.rain>140){
		rainWarn = document.createElement("div");
		rainWarn.style.backgroundColor = "red";
		rainText=this._pointData.num+"-暴雨红色预警"
	}
	if(rainWarn!=null){
		rainWarn.style.padding="3px";
		rainText+="，雨量：【"+this._pointData.rain+"】";
		rainWarn.style.width=rainText.length*12+"px";
		rainWarn.appendChild(document.createTextNode(rainText));
		this._info.push(rainWarn);
		disArr.push(rainWarn);
		div.appendChild(rainWarn);
	}
	
	var snowWarn=null
	var snowText=null;
	if(this._pointData.snow>=10 && this._pointData.snow<20){
		snowWarn = document.createElement("div");
		snowWarn.style.backgroundColor = "#FFB800";
		snowText=this._pointData.num+"-暴雪黄色预警"
	}else if(this._pointData.snow>=20 && this._pointData.snow<30){
		snowWarn = document.createElement("div");
		snowWarn.style.backgroundColor = "#FF5722";
		snowText=this._pointData.num+"-暴雪橙色预警"
	}else if(this._pointData.snow>=30){
		snowWarn = document.createElement("div");
		snowWarn.style.backgroundColor = "red";
		snowText=this._pointData.num+"-暴雪红色预警"
	}
	if(snowWarn!=null){
		snowWarn.style.padding="3px";
		snowText+="，雪量：【"+this._pointData.snow+"】";
		snowWarn.style.width=snowText.length*12+"px";
		snowWarn.appendChild(document.createTextNode(snowText));
		this._info.push(snowWarn);
		disArr.push(snowWarn);
		div.appendChild(snowWarn);
	}
	
	var visWarn=null
	var visText=null;
	if(this._pointData.vis>0.25 && this._pointData.vis<=0.5){
		visWarn = document.createElement("div");
		visWarn.style.backgroundColor = "#FFB800";
		visText=this._pointData.num+"-大雾黄色预警"
	}else if(this._pointData.vis>0.1 && this._pointData.vis<=0.25){
		visWarn = document.createElement("div");
		visWarn.style.backgroundColor = "#FF5722";
		visText=this._pointData.num+-"大雾橙色预警"
	}else if(this._pointData.vis<=0.1){
		visWarn = document.createElement("div");
		visWarn.style.backgroundColor = "red";
		visText=this._pointData.num+"-大雾红色预警"
	}
	if(visWarn!=null){
		visWarn.style.padding="3px";
		visText+="，能见度：【"+this._pointData.vis+"】";
		visWarn.style.width=visText.length*12+"px";
		visWarn.appendChild(document.createTextNode(visText));
		this._info.push(visWarn);
		disArr.push(visWarn);
		div.appendChild(visWarn);
	}
	
	var freezWarn=null
	var freezText=null;
	if(this._pointData.freez==1){
		freezWarn = document.createElement("div");
		freezWarn.style.backgroundColor = "#FFB800";
		freezText=this._pointData.num+"-凝冻黄色预警"
	}else if(this._pointData.freez==2){
		freezWarn = document.createElement("div");
		freezWarn.style.backgroundColor = "#FF5722";
		freezText=this._pointData.num+"-凝冻橙色预警"
	}else if(this._pointData.freez ==3){
		freezWarn = document.createElement("div");
		freezWarn.style.backgroundColor = "red";
		freezText=this._pointData.num+"-凝冻红色预警"
	}
	if(freezWarn!=null){
		freezWarn.style.padding="3px";
		freezText+="，次数：【"+this._pointData.ct+"】";
		freezWarn.style.width=visText.length*12+"px";
		freezWarn.appendChild(document.createTextNode(freezText));
		this._info.push(freezWarn);
		disArr.push(freezWarn);
		div.appendChild(freezWarn);
	}
	
	if(this._info.length==0){
		var info=this._info[0] = document.createElement("div");
		var text=this._pointData.num+"-无灾害";
		info.style.padding="3px";
		info.style.backgroundColor = "#009688";
		info.style.width=text.length*12+"px";
		info.appendChild(document.createTextNode(text));
		div.appendChild(info);
	}
	var that = this;

	var arrow = this._arrow = document.createElement("div");
	var lastBack=this._info[this._info.length-1].style.backgroundColor;
	if(lastBack=='rgb(0, 150, 136)'){
		arrow.style.background = "url('webpage/cn/net/awit/ledScreen/greenLab.png') no-repeat";
	}else if(lastBack=='rgb(255, 184, 0)'){
		arrow.style.background = "url('webpage/cn/net/awit/ledScreen/yellowLab.png') no-repeat";
	}else if(lastBack=='rgb(255, 87, 34)'){
		arrow.style.background = "url('webpage/cn/net/awit/ledScreen/orangeLab.png') no-repeat";
	}else if(lastBack=='red'){
		arrow.style.background = "url('webpage/cn/net/awit/ledScreen/redLab.png') no-repeat";
	}
	arrow.style.position = "absolute";
	arrow.style.width = "12px";
	arrow.style.height = "10px";
	arrow.style.top = (this._info.length*25-3)+"px";
	arrow.style.left = "2px";
	arrow.style.overflow = "hidden";
	div.appendChild(arrow);

	var thatForcast = this._forcast;
	//由于onclick事件只能在pc响应，手机上响应ontouchstart
	div.onclick=function(){
		
	}
	map.getPanes().labelPane.appendChild(div);
	return div;
}
ComplexCustomOverlay.prototype.draw = function() {
	var map = this._map;
	var pixel = map.pointToOverlayPixel(this._point);
	this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
	this._div.style.top = pixel.y - 30 + "px";
}